package com.czwj.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import com.czwj.interceptor.SessionTimeoutInterceptor;

@SpringBootConfiguration
public class WebAppConfig extends WebMvcConfigurationSupport{
	@Value("${resources.phypath}")
	private String ResourcesPath;
	
	public void addInterceptors(InterceptorRegistry registry){
		// registry.addInterceptor(new SessionTimeoutInterceptor()).addPathPatterns("/**.do");
		registry.addInterceptor(new SessionTimeoutInterceptor()).addPathPatterns("/**.do").addPathPatterns("/app/**.do")
				.excludePathPatterns("/app/login.do").excludePathPatterns("/login.do").excludePathPatterns("/logout.do")
				.excludePathPatterns("/test4.do");
	}
	
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry){
		registry.addResourceHandler("/**").addResourceLocations("classpath:/");
		registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
		registry.addResourceHandler("/resources/**").addResourceLocations("file:" + ResourcesPath);
		super.addResourceHandlers(registry);
	}
	
	@Bean
	public MultipartResolver multipartResolver(){
		CustomMultipartResolver multipartResolver = new CustomMultipartResolver();
		multipartResolver.setMaxUploadSize(500000000);
		multipartResolver.setDefaultEncoding("UTF-8");
		return multipartResolver;
	}
	
/*	@Override
	public void addCorsMappings(CorsRegistry registry){
		registry.addMapping("/**").allowedOrigins("*").allowCredentials(true)
				.allowedMethods("GET","POST","DELETE","PUT").maxAge(3600);

	}*/
}
